#!/bin/bash

#==============================================================================
# UV Environment Setup for transcribe-anything
# Creates Python 3.11 venv, installs dependencies, creates activation symlinks
#==============================================================================

# Enable error handling and command tracing
set -e
set -x

# Create virtual environment and install dependencies
uv venv --python 3.11
uv pip install -r requirements.testing.txt
uv pip install -e . --refresh-package uv-iso-env

# Finalize installation
uv run python -c "import os; _ = os.getcwd()"
set +e

# Remove existing activation symlink
if [ -f activate ]; then
    rm activate
fi

# Create platform-specific activation symlink
if [[ "$OSTYPE" == "linux-gnu"* || "$OSTYPE" == "darwin"* ]]; then
    ln -s .venv/bin/activate activate
else
    ln -s .venv/Scripts/activate activate
fi

# Windows compatibility: link bin -> Scripts
if [[ "$OSTYPE" == "msys" ]]; then
    if [ -d .venv/bin ]; then
        rm -rf .venv/Scripts
        ln -s bin .venv/Scripts
    fi
fi
